<template>
  <n-config-provider :date-locale="dateZhCN" :locale="zhCN">
    <n-message-provider>
      <n-notification-provider>
        <n-dialog-provider>
          <router-view v-if="isRouterActive"/>
        </n-dialog-provider>
      </n-notification-provider>
    </n-message-provider>
  </n-config-provider>
</template>

<script setup>
import {NConfigProvider} from 'naive-ui'
import {zhCN, dateZhCN} from 'naive-ui'
import {nextTick, ref, provide, onMounted} from "vue";
import {getMd5secretKey, getTaskStatusEnum} from "./api/commonApi.js";
import {delStorageItem, setStorageString} from "./utils/localStorage.js";
import {useRouter} from "vue-router";

const isRouterActive = ref(true)
const secretKey = ref(null)
const taskStatusOptions = ref([])

provide('reload', () => {
  isRouterActive.value = false
  nextTick(() => {
    isRouterActive.value = true
  })
})

provide('secretKey', ':C0a(D?G%?WZSkK')
provide('taskStatusOptions', taskStatusOptions)
provide('getStatusTagType', taskStatus2TagType)

onMounted(() => {
  getTaskStatusEnum().then(resp => {
    for (const item of resp.data) {
      taskStatusOptions.value.push({label: item.name, value: item.code})
    }
  }).catch(err => {
    console.log(err)
  })
})

function taskStatus2TagType(status) {
  switch (status) {
    case 1:
      return ''
    case 2:
      return 'warning'
    case 3:
      return 'info'
    case 4:
      return 'success'
    default:
      return 'error'
  }
}

</script>

<style scoped>
</style>
